package com.idearworld.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.idearworld.beans.QueryBean;
import com.idearworld.dao.BlogCommentMapper;
import com.idearworld.model.BlogComment;
import com.idearworld.model.BlogCommentExample;
import com.idearworld.service.BlogCommentService;

@Service
public class BlogCommentServiceImpl implements BlogCommentService{

	@Autowired
	private BlogCommentMapper blogCommentMapper;
	
	@Override
	public BlogComment createBlogComment(BlogComment blogComment) {
		if(blogComment == null || blogComment.getBlogId() == null 
			|| blogComment.getContent() == null || blogComment.getContent().equals("")){
			return null;
		}
		blogCommentMapper.insert(blogComment);
		return blogComment;
	}

	@Override
	public List<BlogComment> queryBlogComment(QueryBean queryBean) {
		BlogCommentExample example=new BlogCommentExample();
		if(queryBean !=null && queryBean.getBlogId()>0){
			example.or().andBlogIdEqualTo(queryBean.getBlogId());
		}else{
			example.setOrderByClause(" create_date desc limit 0,10 ");
		}
		
		return blogCommentMapper.selectByExample(example);
	}

	

}
